'use strict'

const { ApiController } = require('jax')

class Controller extends ApiController {
  // 模型
  get Model() {
    return this.ctx.model.ArticleCategory
  }

  // 匹配查询
  get searchKey() {
    return ['app', 'categoryId']
  }

  // 模糊查询
  get likeKey() {
    return ['categoryName']
  }

  // 返回JSON字段
  get json() {
    return ['id', 'categoryName']
  }

  // 分页
  get isPage() {
    return false
  }

  // 查询前
  async beforeIndex() {
    const filter = {
      isOpen: true,
    }

    return {
      filter,
      sort: {
        isTop: 'DESC',
        rank: 'ASC',
      },
    }
  }
}

module.exports = Controller
